package day16;

public class Bank {
    private int account = 10000;
    public void setAccount(int account) {
        this.account = account;
    }
    public int getAccount() {
        return account;
    }


    //定义一个取钱的方法
    public synchronized boolean getMoney(int money) {
        int account = getAccount();
        if (account >= money){
            account -= money;
            Thread.yield(); //模拟当前线程时间片让出
            setAccount(account);
            System.out.println("取款成功，月为" + account);
            return true;
        }
        if (account < money) {
            System.out.println("取款失败！账户月不足" + getAccount());
            return false;
        }
        return false;
    }
}
